<!DOCTYPE html>
<html lang="en">
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
    <!-- 引入组件库 -->
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script src="../plugins/echarts/echarts.js"></script>
</head>
<body class="hold-transition">
<div id="app">
    <div class="box">
        <h2>会员统计</h2>
        <div class="content-header">
            <template>
                <span class="demonstration">日期</span>
                <el-date-picker
                        v-model="formData.value2"
                        type="daterange"
                        unlink-panels
                        range-separator="至"
                        start-placeholder="开始日期"
                        end-placeholder="结束日期"
                        :picker-options="pickerOptions"
                        value-format="yyyy-MM">
                </el-date-picker>

                &nbsp; &nbsp; &nbsp; &nbsp;
                <span>统计类型</span>
                <el-select v-model="formData.value" placeholder="请选择" >
                    <el-option
                            label="新增会员"
                            value="1" @click.native="changeType()">
                    </el-option>
                    <el-option
                            label="预约人数"
                            value="2" @click.native="changeType2()">
                    </el-option>
                </el-select>
            </template>
        </div>
        <div class="app-container">
            <div class="box">
                <!-- 为 ECharts 准备一个具备大小（宽高）的 DOM -->
                <div id="chart1" style="height:400px;"></div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">

    var vue = new Vue({
        el: "#app",
        data: {
            formData: {},
            value2:"",
            pickerOptions: {
                shortcuts: [{
                    text: '最近一周',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近一个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                        picker.$emit('pick', [start, end]);
                    }
                }, {
                    text: '最近三个月',
                    onClick(picker) {
                        const end = new Date();
                        const start = new Date();
                        start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                        picker.$emit('pick', [start, end]);
                    }
                }]
            },
            //下拉框绑定单击事件
            changeType() {
                axios.post("/member/getMemberCount.do",this.formData.value2).then((res)=>{
                    var myChart1 = echarts.init(document.getElementById('chart1'));
                    myChart1.setOption(
                        {
                            title: {
                                text: '会员数量'
                            },
                            tooltip: {},
                            legend: {
                                data:['会员数量']
                            },
                            xAxis: {
                                data:  res.data.data.months
                            },
                            yAxis: {
                                type:'value'
                            },
                            series: [{
                                name: '会员数量',
                                type: 'line',
                                data:  res.data.data.memberCount
                            }]
                        });
                }).catch((r)=>{
        if(r == 'Error: Request failed with status code 403'){
            //权限不足
            alert('无访问权限');
            return;
        }else{
            alert('未知错误');
            return;
        }
    });
            },
            changeType2() {
                axios.post("/member/getOrderCount.do",this.formData.value2).then((res)=>{
                    var myChart1 = echarts.init(document.getElementById('chart1'));
                    myChart1.setOption(
                        {
                            title: {
                                text: '预约人数'
                            },
                            tooltip: {},
                            legend: {
                                data:['预约人数']
                            },
                            xAxis: {
                                data: res.data.data.months
                            },
                            yAxis: {
                                type:'value'
                            },
                            series: [{
                                name: '预约人数',
                                type: 'line',
                                data: res.data.data.orderCount
                            }]
                        });
                }).catch((r)=>{
                    if(r == 'Error: Request failed with status code 403'){
                        //权限不足
                        alert('无访问权限');
                        return;
                    }else{
                        alert('未知错误');
                        return;
                    }
                });
            }
        }
        });


</script>

</html>